package com.runyun.project.service.impl;

import com.runyun.project.entity.User;
import com.runyun.project.mapper.UserMapper;
import com.runyun.project.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @ClassName UserServiceImpl
* @Description (User)表服务实现类
**/
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

   /**
    * @Description 添加User
    */
   @Override
   public boolean insert(User user) {
       if(userMapper.insert(user) == 1){
           return true;
       }
       return false;
   }

   /**
    * @Description 删除User
    */
   @Override
   public boolean deleteById(Integer userId) {
       if(userMapper.deleteById(userId) == 1){
           return true;
       }
       return false;
   }

   /**
    * @Description 查询单条数据
    */
   @Override
   public User queryById(Integer userId) {
       return userMapper.queryById(userId);
   }


    /**
     * @Description 通过邮箱查询单条数据
     */
    @Override
    public User getUserByEmail(String email) {
        return userMapper.getUserByEmail(email);
    }

    /**
     * @Description 通过邮箱和密码查询单条数据
     */
    @Override
    public User queryByEmailAndPwd(String email, String password) {
        return userMapper.queryByEmailAndPwd(email,password);
    }

    /**
    * @Description 查询全部数据
    */
   @Override
   public List<User> queryAll() {
       return userMapper.queryAll();
   }

   /**
    * @Description 实体作为筛选条件查询数据
    */
   @Override
   public List<User> queryAll(User user) {
       return userMapper.queryAll(user);
   }

   /**
    * @Description 修改数据，哪个属性不为空就修改哪个属性
    */
   @Override
   public boolean update(User user) {
       if(userMapper.update(user) == 1){
           return true;
       }
       return false;
   }


    /**
     * @Description 获得已注册用户的数量
     **/
    @Override
    public Integer getUsersCount() {
        return userMapper.getUsersCount();
    }

}